package org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.domain.AbstractAggregateRoot;
import org.springframework.util.Assert;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.event.CreateActivityLinkItemEvent;

import java.io.Serial;
import java.io.Serializable;

@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "item_to_activity")
@AllArgsConstructor
@Data
public class ActivityToItem extends AbstractAggregateRoot<ActivityToItem> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private Integer activityId;
    private Integer itemId;

    public ActivityToItem() {}

    public static ActivityToItem of(Integer activityId, Integer itemId) {
        Assert.notNull(activityId, "activityId must not be null");
        Assert.notNull(itemId, "itemId must not be null");
        ActivityToItem rel = new ActivityToItem();
        rel.activityId = activityId;
        rel.itemId = itemId;
        return rel;
    }
    public void add(){
        registerEvent(new CreateActivityLinkItemEvent(this));
    }
}